<template>
		<Card v-model="addPromotersJabe" class="shouka addPromotercard" width="95%">
		     <p>剩余房卡:{{keyNum}}</p>
		     <br/>
         <ul class="addcardul">
           <li>
             <label>玩家ID:</label>
             <Input v-model="tUId" class="tabs-input addcardinput"></Input>
           </li>
           <li>
             <label>数&nbsp;&nbsp;&nbsp;量:</label>
             <Input v-model="tKeyNum" class="tabs-input addcardinput"></Input>
           </li>
           <li>
            <Button html-type="reset" @click="onPromoterreset" class="addcardbutton">撤销</Button>
            <span>&nbsp;</span>
            <Button type="primary" @click="onaddJabeSubmit" size="large" class="addcardbutton">提交</Button>
           </li>
         </ul>
		</Card>	
</template>
<script>
import {getVO} from '@/common/proto-vo.js'
import {addPromoterRoomCardNum} from '@/api/promoters.js'
import {getUserBindUId, getUId, getUserBindUserName} from '@/common/auth'
import {getRoleBaseInfo} from '@/api/game.js'
export default {
  data () {
    return {
      tableData: [],
      myPlayerTableData: [],
      sellRecordData: [],
      buyRecordData: [],
      userList: [],
      pUserList: [],
      crtPage: 1,
      totalPage: 0,
      pageSize: 10,
      crtSellPage: 1,
      totalSellPage: 0,
      sellPageSize: 10,
      crtBuyPage: 1,
      totalBuyPage: 0,
      buyPageSize: 10,
      crtMyPlayerPage: 1,
      totalMyPlayerPage: 0,
      myPlayerPageSize: 10,
      uId: '',
      uid: '',
      pUid: '',
      pUserName: '未有上线',
      userName: '',
      tUId: '',
      keyNum: 0,
      tKeyNum: 1,
      dayAddNum: 0,
      dayActiveNum: 0,
      dayUseNum: 0,
      selectType: 0,
      addPromotersModal: false,
      bindUserNameModal: false,
      addPPromotersModal: false,
      addPromotersJabeModal: false,
      promotersMgrLab: (h) => {
        return h('div', [
          h('Button', [h('Img', {
            props: {
              src: 'logos',
              size: '110',
              color: '#459498'
            },
            style: {
              fontSize: '30px',
              width: '25px',
              height: '100px',
              marginBottom: '30px'
            }
          }), h('Label', {
            style: {
              fontSize: '20px',
              color: '#1881B1',
              width: '10px',
              height: '50px'
            }
          }, '代理首页')], {
            style: {
              width: '100px',
              height: '100px'
            }}
            )
        ])
      },
      myPromotersLab: (h) => {
        return h('div', [
          h('Button', {
            props: {
              type: 'info'
            },
            style: {
              width: '100px',
              height: '50px'
            }
          }, '我的下线')
        ])
      },
      myBuyersLab: (h) => {
        return h('div', [
          h('Button', {
            props: {
              type: 'info'
            },
            style: {
              width: '100px',
              height: '50px'
            }
          }, '我的买家')
        ])
      },
      roomCardBuyRecordLab: (h) => {
        return h('div', [
          h('Button', {
            props: {
              type: 'info'
            },
            style: {
              width: '100px',
              height: '100px',
              background: ''
            }
          }, '购买记录')
        ])
      },
      roomCardSellRecordLab: (h) => {
        return h('div', [
          h('Button', {
            props: {
              type: 'info'
            },
            style: {
              width: '100px',
              height: '100px'
            }
          }, '出售记录')
        ])
      }
    }
  },
  created () {
    this.addPromotersJabe()
    this.mySearch()
  },
  methods: {
    mySearch () {
      let selfId = getUserBindUId()
      let selfName = getUserBindUserName()
      console.log('mySearch selfId:', selfId, 'selfName:', selfName)
      getRoleBaseInfo(selfId, selfName).then((data) => {
        if (!data || data === 'undefined') {
          return
        }
        console.log('mySearch get data selfId:', selfId, 'selfName:', selfName, ' ,data:', data.data.data.data[0])
        let RoleBaseInfoVO = getVO('RoleBaseInfoVO')
        // let pv = data.data.data
        let vo = RoleBaseInfoVO.decode(data.data.data.data[0])
        this.keyNum = vo.jabe
        let bindUId = getUserBindUId()
        let uId = getUId()
        console.log('bindUId:', bindUId, 'uId:', uId)
      })
      // }
    },
    addPromotersJabe () {
      let selfId = getUserBindUId()
      let selfName = getUserBindUserName()
      getRoleBaseInfo(selfId, selfName).then((data) => {
        if (!data) {
          return
        }
        let RoleBaseInfoVO = getVO('RoleBaseInfoVO')
        let pv = data.data.data
        let vo = RoleBaseInfoVO.decode(pv.data[0])
        this.keyNum = vo.jabe
      })
    },
    onaddJabeSubmit () {
      let sellNum = parseInt(this.tKeyNum)
      console.log('onAddJabeSubmit tUId=', this.tUId, ',tKeyNum=', sellNum)
      addPromoterRoomCardNum(this.tUId, sellNum).then((data) => {
        if (!data) {
          this.$router.push('AddPromotersJabeFail')
          return
        }
        let success = data.data.data.intValues[0]
        if (success === 1) {
          this.keyNum = parseInt(this.keyNum) - sellNum
          // this.$Message.info('划账成功!!!')
          // window.location.reload()
          this.$router.push('AddPromotersJabeSuccess')
        } else {
          // this.$Message.error('划账失败!!!')
          this.$router.push('AddPromotersJabeFail')
        }
      })
    },
    onPromoterreset () {
      this.tUId = ''
      this.tKeyNum = ''
    }
  }
}
</script>
<style>
  .addcardinput{
    width: 500px;
    height: 60px;
  }
  .addcardinput input{
    height: 100%;
    font-size: 40px;
  }
  .addcardul li{
    text-align: center;
    margin-top: 20px;
  }
  .addcardbutton{
    font-size: 30px;
    padding:10px 20px;
    margin-top: 30px;
  }
  .addPromotercard{
    margin: 30px;
    font-size: 40px;
  }
</style>
